package com.demo;

import com.google.gson.Gson;
import org.junit.Test;

/**
 * @author WuLiangHang
 */
public class Test01 {
    @Test
    public void test01() {
        Person p = new Person(1, 18, "小明", 'M');
        Gson gson = new Gson();
        //将javabean转换成json字符串
        String jsonStr = gson.toJson(p);
        System.out.println(jsonStr);
        //json字符串转成javabean
        Person person = gson.fromJson(jsonStr, Person.class);
        System.out.println(person);
    }
}
